//
//  HJEditUserNameViewController.m
//  Sneakers
//
//  Created by 胡光健 on 2017/11/21.
//  Copyright © 2017年 mac. All rights reserved.
//

#import "HJEditUserNameViewController.h"

@interface HJEditUserNameViewController ()
@property (weak, nonatomic) IBOutlet UIButton *save;
@property (weak, nonatomic) IBOutlet UITextField *username;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *btmH;
@end

@implementation HJEditUserNameViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.title = @"修改昵称";
    self.save.layer.shadowOpacity = 0.2;
    self.save.layer.shadowRadius = 3;
    self.save.layer.shadowOffset = CGSizeZero;
    self.save.layer.shadowColor = [UIColor blackColor].CGColor;
    [[self.username.rac_textSignal filter:^BOOL(NSString*text){
        return text.length >=16;
    }] subscribeNext:^(NSString *text){
        self.username.text = [text substringToIndex:16];
    }];
}

- (IBAction)save:(UIButton *)sender {
    if ([CommonTools inputChineseOrLettersAndNumbersNum:self.username.text] || [CommonTools inputShouldLetterOrNum:self.username.text]) {
        if (self.username.text.length>=4 && self.username.text.length<=16) {
            if (self.editUserNameBlock) {
                self.editUserNameBlock(self.username.text);
            }
            dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
                [mNotificationCenter postNotificationName:@"editmemberNotification" object:nil userInfo:@{@"nickname":self.username.text}];
            });
            [self.navigationController popViewControllerAnimated:YES];
        }else {
            [self showErrorHUDWithError:@"请输入4-16个字符"];
        }
    }else {
        [self showErrorHUDWithError:@"昵称不符合要求，请重新输入"];
    }
}

@end
